<?php

namespace console\models;

use common\helpers\FileHelper;
use common\models\BaseUser;
use common\models\user\UserFollower;
use Yii;

/**
 * This is the model class for table "{{%user}}".
 *
 * @property int $id
 * @property string $username
 * @property string $mobile
 * @property string $email
 * @property string $auth_key
 * @property string $password_hash
 * @property string $password_reset_token
 * @property string $ip
 * @property int $status
 * @property string $created_at
 * @property string $updated_at
 * @property string $deleted_at
 */
class UserForDynamicLogic extends BaseUser {
    public function fields() {
        return [
            'id',
            'username',
            'email',
            'mobile' => function () {
                return ($this->meta && $this->meta->mobile) ? true : null;
            },
            'avatar' => function () {
                return $this->meta ? $this->meta->avatar : '';
            },
            'cover' => function () {
                return $this->meta ? $this->meta->cover : '';
            },
            'followed',
        ];
    }

    public function setUserId($id){
        $this->id = $id;
        return $this;
    }

    public function getFollowed() {
        return $this->hasOne(UserFollower::className(), ['followed_user_id' => 'id'])->andWhere([
            'user_id' => $this->id
        ])->exists();
    }
}
